package com.qiaoba.module.system.converter;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qiaoba.module.system.entity.SysDept;
import com.qiaoba.module.system.entity.dto.SysDeptDTO;
import com.qiaoba.module.system.entity.param.SysDeptParam;

/**
 * 部门 类型转换
 *
 * @author ailanyin
 * @date 2023-09-10 22:01:25
 */
public class SysDeptConverter {

    public static SysDept dto2Entity(SysDeptDTO dto) {
        SysDept sysDept = new SysDept();
        sysDept.setDeptId(dto.getDeptId());
        sysDept.setParentId(dto.getParentId());
        sysDept.setDeptName(dto.getDeptName());
        sysDept.setOrderNum(dto.getOrderNum());
        sysDept.setLeader(dto.getLeader());
        sysDept.setPhone(dto.getPhone());
        sysDept.setEmail(dto.getEmail());
        sysDept.setStatus(dto.getStatus());
        sysDept.setRemark(dto.getRemark());
        return sysDept;
    }

    public static QueryWrapper<SysDept> param2Wrapper(SysDeptParam param) {
        QueryWrapper<SysDept> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .orderByAsc(SysDept::getOrderNum)
                .like(StrUtil.isNotBlank(param.getDeptName()), SysDept::getDeptName, param.getDeptName())
                .eq(StrUtil.isNotBlank(param.getStatus()), SysDept::getStatus, param.getStatus());
        return wrapper;
    }
}
